package zhao.tx.eecs.Tools;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;


import org.apache.http.cookie.Cookie;


/**
 * Created by ishishuji on 14-7-18.
 */
public class SharedPreferencesHelper {

    private static SharedPreferences sp;

    private static Editor editor;


    public static boolean isFirst ( Context context ) {
        sp = context.getSharedPreferences ( "isFirst",-1 );

        return sp.getBoolean ( "isFirst",true );
    }

    public static void setFirst ( Context context ) {
        sp = context.getSharedPreferences ( "isFirst",-1 );
        editor = sp.edit ();
        editor.putBoolean ( "isFirst",false );
        editor.commit ();
    }

    public static String getCookie ( Context context ) {
        sp = context.getSharedPreferences ( "cookie",-1 );

        return sp.getString ( "cookie",null);
    }

    public static void setCookie ( Context context , String cookie ) {
        sp = context.getSharedPreferences ( "cookie",-1 );
        editor = sp.edit ();
        editor.putString ( "cookie",cookie );
        editor.commit ();
    }

    public static boolean isCookieExists ( Context context ) {
        sp = context.getSharedPreferences ( "cookie",-1 );
        if ( sp.getString ( "cookie","" ).equals ( "" ) ) {
            return false;
        } else {
            return true;
        }
    }

    public static long getMaxAge ( Context context ) {
        sp = context.getSharedPreferences ( "maxAge",-1 );

        return sp.getLong ( "maxAge",0L);
    }

    public static void setMaxAge ( Context context , long cookie ) {
        sp = context.getSharedPreferences ( "maxAge",-1 );
        editor = sp.edit ();
        editor.putLong ( "maxAge",cookie );
        editor.commit ();
    }

    public static boolean isMaxAgeExists ( Context context ) {
        sp = context.getSharedPreferences ( "maxAge",-1 );
        if ( sp.getLong ( "maxAge",0l ) != 0L ) {
            return false;
        } else {
            return true;
        }
    }

}
